﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DevComponents.AdvTree;

namespace project_assess.assess_relate
{
    public partial class input_frm : Office2007Form
    {
        DataBase m_db;
        string type;
        string id;
        public input_frm(DataBase db, string t, string i)
        {
            InitializeComponent();
            m_db = db;
            type = t;
            this.Text = "请输入" + type;
            id = i;
        }

        private void btnno_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnok_Click(object sender, EventArgs e)
        {
            double val = doubleInput.Value;
            message_frm frm;
            if (val <= 0)
            {
                frm = new message_frm("输入值不能为0以下", "错误", icon_img.warning);
                frm.ShowDialog(this);
                frm.Close();
                return;
            }
            string sql; 
            sql = "select max([次数]) from [assess_predict] where [项目编号]='" + id
                + "' and [控制成本]='" + type + "'";
            DataTable dt = m_db.GetDataSet(sql).Tables[0];
            double no = 1;
            if (dt == null || dt.Rows.Count == 0)
            {
                no = 1;
            }
            else
            {
                try
                {
                    no = Convert.ToInt32(dt.Rows[0][0]) + 1;
                }
                catch
                {
                    no = 1;
                }
            }
            sql = "insert into [assess_predict] values('" + id + "','" + type + "'," + val + ","
                + no + ",'" + DateTime.Now.ToShortDateString() + "','','','','')";
            m_db.ExecuteSQL(sql);
            this.Close();
        }
    }
}
